<template>
	<view class="page">
		<fu-custom :isBack="true" :isBottom="true" bgColor="bg-white">
			<view slot="content">{{i18n['账号与安全']}}</view>
		</fu-custom>
		<view class="fu-fs28">
			<!-- #ifndef MP-WEIXIN -->
			<!-- 修改密码 start -->
			<view class="padding-lr bg-white" @tap="handleJump" data-url="/pages/index/setting/modify-password/index">
				<view class="flex align-center justify-between padding-tb solid-bottom">
					<text class="fu-fs32 text-333">{{i18n['修改密码']}}</text>
					<text class="cuIcon-right"></text>
				</view>
			</view>
			<!-- 修改密码 end -->
			<!-- #endif -->
			
			<!-- 修改支付密码 start -->
			<view class="padding-lr bg-white" @tap="handleJump" data-url="/pages/index/setting/modify-pay-password/index" v-if="!setPass">
				<view class="flex align-center justify-between padding-tb solid-bottom">
					<text class="fu-fs32 text-333">{{i18n['修改支付密码']}}</text>
					<text class="cuIcon-right"></text>
				</view>
			</view>
			<!-- 修改支付密码 end -->
			<!-- 设置支付密码 start -->
			<view class="padding-lr bg-white" @tap="handleJump" data-url="/pages/index/setting/change-pay-password/index" v-else>
				<view class="flex align-center justify-between padding-tb solid-bottom">
					<text class="fu-fs32 text-333">{{i18n['设置支付密码']}}</text>
					<text class="cuIcon-right"></text>
				</view>
			</view>
			<!-- 设置支付密码 end -->
			
			<!-- #ifndef MP-WEIXIN -->
			<!-- 更换手机号 start -->
			<view class="padding-lr bg-white" @tap="handleJump" data-url="/pages/index/setting/modify-password-verify-phone/index?type=3">
				<view class="flex align-center justify-between padding-tb solid-bottom">
					<text class="fu-fs32 text-333">{{i18n['修改绑定手机号']}}</text>
								<text class="cuIcon-right"></text>
				</view>
			</view>
			<!-- 更换手机号 end -->
			<!-- #endif -->
			
			<view class="padding-lr bg-white margin-top-sm">
				<view class="height-110 line-height-110 text-333 fu-fs32 text-center" @tap="cancelAcount">注销账号</view>
			</view>
		</view>
		
		<!-- APP更新组件 start -->
		<app-update ref="update"></app-update>
		<!-- APP更新组件 end -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				setPass: false, //设置支付密码
				status:'',//注销状态
			};
		},
		onLoad() {
			this.addTime();
      this.getData();
			uni.$on('setPass', (data) => {
				this.addTime();
			});
			uni.$on('cancelAccount',data=>{
				this.getData();
			});
		},
		methods: {
			// 注销账号
			cancelAcount(){
				if(this.status === -1 || this.status === 2){
          this.$urouter.navigateTo({
						url: '/pages/index/setting/cancel-account/cancel-account/index'
					})
				}else if(this.status === 0){
          this.$urouter.navigateTo({
          	url: '/pages/index/setting/cancel-account/cancel-loading/index'
          })
				}
			},
			// 获取协议和状态
			getData() {
				this.$api.post(global.apiUrls.cancelAccountAgreement).then(res => {
					if (res.data.code == 1) {
						this.status = res.data.data;
					} else {
            this.$message.info(res.data.msg);
					}
				}).catch(()=>{
				})						
			},
			/**
			 * @function
			 * @description 判断用户是否设置支付密码
			 * @property {Number} pay_money - 订单金额
			 */
			addTime() {
				this.$api.post(global.apiUrls.isSetPay).then((res) => {
					if (res.data.code == 1) {
						if (res.data.data.falg == 0) {
							this.setPass = true;
						}
					}
				})
			},
		}
	};
</script>

<style lang="scss" scoped>
</style>
